<script setup>
import { onBeforeUnmount,ref } from 'vue';
import emitter from '../utils/bus';

let message = ref()

emitter.on('sendDataTo1', (data) => {
  message.value = data.msg
})

onBeforeUnmount(() => {
  emitter.off('sendDataTo1')
})
</script>

<template>
  <div>
    <h2>组件1</h2>
    <div>收到的消息：{{ message }}</div>
  </div>
</template>
